package org.xiyu.yee.beacon_anti_phantom.mixin;

import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.monster.Phantom;
import net.minecraft.world.level.Level;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.xiyu.yee.beacon_anti_phantom.beacon.BeaconManager;
import org.xiyu.yee.beacon_anti_phantom.Constants;

@Mixin(Phantom.class)
public class PhantomSpawnMixin {

    @Inject(method = "<init>", at = @At("TAIL"))
    private void onPhantomConstruct(EntityType<? extends Phantom> entityType, Level level, CallbackInfo ci) {
        // 现在只用于日志记录，实际处理在ServerChunkCacheMixin中
        Phantom phantom = (Phantom) (Object) this;
        
        if (!level.isClientSide() && level instanceof ServerLevel) {
            BlockPos pos = phantom.blockPosition();
            
            if (BeaconManager.getInstance().isInBeaconRange(pos)) {
                Constants.LOG.debug("Phantom spawned at {} in beacon protection area, will be handled by ServerChunkCacheMixin", pos);
            }
        }
    }
}
